package com.handpay.zztong.hp.notification.activity;

import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.handpay.framework.utils.CommonUtils;
import com.handpay.zztong.hp.R;
import com.handpay.zztong.hp.base.activity.ZZTongActivity;
import com.handpay.zztong.hp.bean.ActionBar;
import com.handpay.zztong.hp.notification.bean.PushMessgaeBody;
import com.handpay.zztong.hp.notification.model.PushMessageModel;
import com.handpay.zztong.hp.notification.widget.XRTextView;
import com.handpay.zztong.hp.utils.AccountUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by fplei on 2017/5/17.
 * 推送消息
 */

public class PushDetailActivity extends ZZTongActivity {
    private RecyclerView mRecyclerView;

    @Override
    public ActionBar getActivityActionBar() {
        return new ActionBar(getString(R.string.push_detail_message), true);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setContentView(R.layout.activity_pushdetail);
        super.onCreate(savedInstanceState);
        PushMessageModel.getInstance().builder(this.getApplicationContext());
        mRecyclerView = (RecyclerView) findViewById(R.id.push_detail_recycle);
        mRecyclerView.setHasFixedSize(true);
        LinearLayoutManager mLayoutManager = new LinearLayoutManager(this);
        mLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        mRecyclerView.setLayoutManager(mLayoutManager);
        mRecyclerView.setItemAnimator(new DefaultItemAnimator());
        pushMessageAdapter messageAdapter=new pushMessageAdapter();
//        messageAdapter.setPushMessages(PushMessageModel.getInstance().getPushMessages(AccountUtils.getUserId(this)));
        messageAdapter.setPushMessages(PushMessageModel.getInstance().getTestPushMessages());
        mRecyclerView.setAdapter(messageAdapter);
    }

    @Override
    protected boolean isShownTopBar() {
        return true;
    }

    class pushMessageAdapter extends RecyclerView.Adapter<pushMessageAdapter.ItemViewHolder>{
        private List<PushMessgaeBody> pushMessages = new ArrayList<>();
        public void setPushMessages(List<PushMessgaeBody> mData){
            this.pushMessages=mData;
            notifyDataSetChanged();
        }
        @Override
        public ItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            View itemRootView = LayoutInflater.from(parent.getContext()).inflate(R.layout.activity_pushdetail_item, null);
            ItemViewHolder vh=new ItemViewHolder(itemRootView);
            return vh;
        }

        @Override
        public void onBindViewHolder(ItemViewHolder holder, int position) {
            PushMessgaeBody pushMessgaeBody= pushMessages.get(position);
            holder.tv_titile.setText(pushMessgaeBody.getTitle());
            holder.tv_datetime.setText(pushMessgaeBody.getTime());
            holder.tv_content.setText(pushMessgaeBody.getContent());
        }

        @Override
        public int getItemCount() {
            return pushMessages.size();
        }

        class ItemViewHolder extends RecyclerView.ViewHolder{
            TextView tv_titile,tv_datetime;
            XRTextView tv_content;
            LinearLayout linear_detail_context;
            public ItemViewHolder(View itemView) {
                super(itemView);
                tv_titile=(TextView)itemView.findViewById(R.id.tv_titile);
                tv_datetime=(TextView)itemView.findViewById(R.id.tv_datetime);
                tv_content=new XRTextView(PushDetailActivity.this, getResources().getDimension(R.dimen.normal_text_size), Color.rgb(71, 71, 71), CommonUtils.dp2px(20), CommonUtils.dp2px(20), 0, 0);
                linear_detail_context=(LinearLayout)itemView.findViewById(R.id.linear_detail_context);
                linear_detail_context.addView(tv_content);
            }
        }
    }
}
